#include "bo3d.h"


BBDECL Ogre::SceneNode* __stdcall o_entity_getParentSceneNode(Ogre::Entity* entity)
{
	Ogre::SceneNode* node;
	try
	{
		node = entity->getParentSceneNode();
	}
	catch(Ogre::Exception &e)
	{
		std::cout << e.getDescription() << std::endl;
	}
	return node;
}


BBDECL void __stdcall o_entity_setCastShadows(Ogre::Entity* entity, bool castShadows)
{
	try
	{
		entity->setCastShadows(castShadows);
	}
	catch(Ogre::Exception &e)
	{
		std::cout << e.getDescription() << std::endl;
	}
}

BBDECL void __stdcall o_setShadowUseLightClipPlanes(Ogre::SceneManager* scm, bool enable)
{
	try
	{
		scm->setShadowUseLightClipPlanes(enable);
	}
	catch(Ogre::Exception &e)
	{
		std::cout << e.getDescription() << std::endl;
	}
}

BBDECL Ogre::Entity* __stdcall o_clone(Ogre::Entity* entity, const char* entityName)
{
	Ogre::Entity* c;
	try
	{
		c = entity->clone(Ogre::String(entityName));
	}
	catch(Ogre::Exception &e)
	{
		std::cout << e.getDescription() << std::endl;
	}

	return c;
}

BBDECL void __stdcall o_entity_setMaterial(Ogre::Entity* entity, Ogre::Material* mat)
{
	try
	{
		entity->setMaterial(Ogre::MaterialPtr(mat));
	}
	catch(Ogre::Exception &e)
	{
		std::cout << e.getDescription() << std::endl;
	}
}

// Sets the material to use for the whole of this entity. 
BBDECL void __stdcall o_entity_setMaterialName(Ogre::Entity* entity, const char* matName, const char* resGroup)
{
	Ogre::String rG;
	Ogre::String resG = Ogre::String(resGroup);

	if(resG == "DEFAULT_RESOURCE_GROUP_NAME")
	{
		rG = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME;
	}
	else if(resG == "AUTODETECT_RESOURCE_GROUP_NAME")
	{
		rG = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME;
	}
	else if(resG == "INTERNAL_RESOURCE_GROUP_NAME")
	{
		rG = ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME;
	}
	else
	{
		rG = resG;
	}

	try
	{
		entity->setMaterialName(Ogre::String(matName), rG);
	}
	catch(Ogre::Exception &e)
	{
		std::cout << e.getDescription() << std::endl;
	}
}


BBDECL Ogre::Material* __stdcall o_entity_getMaterial(Ogre::Entity* entity, int subEntity)
{
	return entity->getSubEntity(subEntity)->getMaterial().getPointer();
}


BBDECL Ogre::Mesh* __stdcall o_entity_getMesh(Ogre::Entity* entity)
{
	Ogre::MeshPtr mesh;
	try
	{
		mesh = entity->getMesh();
	}
	catch(Ogre::Exception &e)
	{
		std::cout << e.getDescription() << std::endl;
	}

	return mesh.getPointer();
}